////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008 Michiel Helvensteijn                                    //
//                                                                            //
// This file is part of the Mist compiler.                                    //
//                                                                            //
// The Mist compiler is free software: you can redistribute it and/or modify  //
// it under the terms of the GNU General Public License as published by       //
// the Free Software Foundation, either version 3 of the License, or          //
// (at your option) any later version.                                        //
//                                                                            //
// The Mist compiler is distributed in the hope that it will be useful,       //
// but WITHOUT ANY WARRANTY; without even the implied warranty of             //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              //
// GNU General Public License for more details.                               //
//                                                                            //
// You should have received a copy of the GNU General Public License          //
// along with the Mist compiler.  If not, see <http://www.gnu.org/licenses/>. //
////////////////////////////////////////////////////////////////////////////////

#ifndef EXCEPTION_HPP
#define EXCEPTION_HPP

/******************************************************************************
 * Includes                                                                   *
 ******************************************************************************/

#include <exception>
using std::exception;

#include <string>
using std::string;

/******************************************************************************
 * Exception Definition macro                                                 *
 ******************************************************************************/

#define DEFINE_EXCEPTION(ExceptionName, default_message)                   \
	class ExceptionName : public virtual exception {                       \
		public:                                                            \
			ExceptionName(string what = default_message) : _what(what) { } \
			                                                               \
			virtual ~ExceptionName() throw() { }                           \
			                                                               \
			virtual const char* what() const throw() {                     \
				return _what.c_str();                                      \
			}                                                              \
			                                                               \
			virtual const string& message() const throw() {                \
				return _what;                                              \
			}                                                              \
		                                                                   \
		private:                                                           \
			                                                               \
			string _what;                                                  \
	};

#endif // EXCEPTION_HPP
